/*
 *  WaveFunction.h
 *  SoundController0002
 *
 *  Created by jiro on 10/11/11.
 *  Copyright 2010 jiro music. All rights reserved.
 *
 */

#pragma once

#include <limits>
#include <cmath>
#include <string>
#include "Constants.h"
#include "Common/Range.h"

namespace sc {

	/*
		function object, x has linear form
	*/
	class WaveFunction {

		friend class WaveFunctionFactory;

	public:

		enum Type {

			Type_XSineX,
			
			Type_LogXSinX,
			
			Type_SinXVariableCycle,
			
			Type_SinPowerOfX,

		};

	protected:

		Type type;

		double cycle;

		Range definedRangeOfX;

		double normalizer;

		double slopeOfX;

		double interceptOfX;

	public:

		virtual double operator() ( double x ) const = 0;
		
		virtual double GetMaxOfY() const;

		virtual double GetCycle() const;

		virtual bool operator == ( const WaveFunction& rhs ) const;
		
		virtual bool operator != ( const WaveFunction& rhs ) const;
		
		virtual bool operator < ( const WaveFunction& rhs ) const;

		Type GetType() const;
		
		double GetNormailzer() const;

		double GetSlopeOfX() const;
		
		double GetInterceptOfX() const;

		std::string ToString() const;
		
	protected:

		WaveFunction( Type type, double cycle, double normalizer, double slopeOfX, double interceptOfX );

		WaveFunction( Type type, double cycle, Range definedRangeOfX, double normalizer, double slopeOfX, double interceptOfX );

		double ModifyX( double x ) const;

		void SetNormalizer();

	};

}
